package com.huizu.goods.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.huizu.common.annotation.Log;
import com.huizu.common.enums.BusinessType;
import com.huizu.common.core.controller.BaseController;
import com.huizu.common.core.domain.AjaxResult;
import com.huizu.common.utils.poi.ExcelUtil;
import com.huizu.goods.domain.StoreGoods;
import com.huizu.goods.domain.StoreGoodsImage;
import com.huizu.goods.service.IStoreGoodsImageService;
import com.huizu.goods.service.IStoreGoodsService;
import com.huizu.common.core.page.TableDataInfo;

/**
 * 商品轮播图Controller
 * 
 * @author 
 * @date 2020-04-22
 */
@Controller
@RequestMapping("/shop/image")
public class StoreGoodsImageController extends BaseController {
	private String prefix = "shop/image";

	@Autowired
	private IStoreGoodsImageService shopProductImageService;
	
	@Autowired
	private IStoreGoodsService storeGoodsService;


	@GetMapping()
	public String image() {
		return prefix + "/image";
	}

	/**
	 * 查询商品轮播图列表
	 */
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(StoreGoodsImage shopProductImage) {
		startPage();
		List<StoreGoodsImage> list = shopProductImageService.selectShopProductImageList(shopProductImage);
		return getDataTable(list);
	}


	/**
	 * 新增商品轮播图
	 */
	@GetMapping("/edit/{id}")
	public String add(@PathVariable("id") Integer id,ModelMap mmap) {
		StoreGoods storeGoods = storeGoodsService.selectStoreGoodsById(id);
		mmap.put("storeGoods", storeGoods);
		return prefix + "/add";
	}

	/**
	 * 新增保存商品轮播图
	 */
	@Log(title = "商品轮播图", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(StoreGoodsImage shopProductImage) {
		
		return toAjax(shopProductImageService.insertShopProductImage(shopProductImage));
	}

	/**
	 * 删除商品轮播图
	 */
	@Log(title = "商品轮播图", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(shopProductImageService.deleteShopProductImageByIds(ids));
	}
}
